//
//  challengePassMaker.m
//  linkingGame
//
//  Created by 李佳 on 15/4/7.
//  Copyright (c) 2015年 com.jinWu. All rights reserved.
//

#import "ChallengePassMaker.h"
#import "MapMaker.h"

@implementation ChallengePassMaker
+ (ChallengeLevelData*)bulitMapWithLevel: (NSUInteger)level
{
    ChallengeLevelData* levelData = [[ChallengeLevelData alloc] init];
    //1.得到行列数目。
    NSArray* minCloRow = GetMinRowAndCloNumber();
    NSUInteger minClo = [minCloRow[0] intValue];
    NSUInteger minRow = [minCloRow[1] intValue];
    
    NSUInteger cloAddValue = levelData.maxClo - minClo; //增量  分为6次增加完成
    NSUInteger rowAddValue = levelData.maxRow - minRow;
    if (!isPhone())
    {
        levelData.curCloNum = minClo + (level / 5) * (cloAddValue / 6.0);
        levelData.curRowNum = minRow + (level / 5) * (rowAddValue / 6.0);
    }
    else
    {
        levelData.curCloNum = minClo + ((level - 1) / 5) * (cloAddValue);
        levelData.curRowNum = minRow + ((level - 1) / 5) * (rowAddValue);
    }
    
    if (isPhone())
    {
        levelData.typeCount = 8 - (5 - (level % 5));
    }
    else
    {
        levelData.typeCount = 18 - 2 * (5 - (level % 5));
    }

    //2根据当前的产生时间
    //12->开始递减 每5个为一个周期
    if (level % 5 == 0)
    {
        levelData.mapResetTime = 20;
        levelData.addRandPairTime = 10;
    }
    else
    {
        levelData.mapResetTime = 40 - (5 * (level % 5));
        levelData.addRandPairTime = 20 - (3 * (level % 5));
    }
    
    levelData.totalTime = ((levelData.curCloNum * levelData.curRowNum) / 2) * (levelData.mapResetTime - 2) - ((levelData.curCloNum * levelData.curRowNum) / 2) / 4;
    
    //3.根据行列数得到map。
    MapMaker* mapMaker = [[MapMaker alloc] init];
    levelData.gameMapArray = [mapMaker MakeLLKMapWithRow:levelData.curRowNum Cloum:levelData.curCloNum AndIndexCount:levelData.typeCount];
    return levelData;
}
@end
